﻿using AdRotator;
using AdRotator.Model;
using Microsoft.Phone.Controls;
using System.Windows;

namespace AdRotatorExample.WP8
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            AdRotatorControl.SlidingAdDisplaySeconds = 4;
            AdRotatorControl.SlidingAdHiddenSeconds = 2;
            SlidingAdDirectionSelector.Items.Add(SlideDirection.None);
            SlidingAdDirectionSelector.Items.Add(SlideDirection.Left);
            SlidingAdDirectionSelector.Items.Add(SlideDirection.Top);
            SlidingAdDirectionSelector.Items.Add(SlideDirection.Right);
            SlidingAdDirectionSelector.Items.Add(SlideDirection.Bottom);
            AdRotatorControl.Log += new AdRotator.AdRotatorControl.LogHandler(AdRotatorControl_Log);

            Loaded += new RoutedEventHandler(MainPage_Loaded);
            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            AdRotatorControl.Invalidate();
        }

        void AdRotatorControl_Log(string message)
        {
            Dispatcher.BeginInvoke(() => MessagesListBox.Items.Insert(0, message));
        }

        private void Random_Button_Click(object sender, RoutedEventArgs e)
        {
            PageTitle.Text = AdRotatorControl.Invalidate();
        }

        private void Next_Button_Click(object sender, RoutedEventArgs e)
        {
            PageTitle.Text = AdRotatorControl.Invalidate(true);
        }


        // Sample code for building a localized ApplicationBar
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Create a new button and set the text value to the localized string from AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Create a new menu item with the localized string from AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}
    }
}